{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow.compat.v1 as tf \n",
    "tf.disable_eager_execution()\n",
    "import numpy as np\n",
    "import math\n",
    "import collections\n",
    "import pickle as pkl\n",
    "import re\n",
    "import jieba\n",
    "import os\n",
    "import os.path as path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'', '(', '“', '！', '”', '’', '‘', '（', '.', '，', '呢', '了', '…', '？', \"'\", '吧', '。', '、', '）', ')', '\"', '的', '：'}\n"
     ]
    }
   ],
   "source": [
    "tmp_stop_words=[]\n",
    "stop_words = set()\n",
    "with open(\"corpus/stop_words.txt\") as sw:\n",
    "    line = sw.readline()\n",
    "    while line:\n",
    "        tmp_stop_words.append(line[:-1])\n",
    "        line=sw.readline()\n",
    "\n",
    "\n",
    "\n",
    "# for item in tmp_stop_words:\n",
    "stop_words |= set(tmp_stop_words) #去掉重复的\n",
    "\n",
    "print(stop_words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16408\n"
     ]
    }
   ],
   "source": [
    "raw_words = []\n",
    "raw_word_list=[]\n",
    "sentence_list=[]\n",
    "with open(\"corpus/BaiYeXing.txt\") as tr:\n",
    "    line = tr.readline()\n",
    "    while line:\n",
    "        while '\\n' in line:\n",
    "            line= line.replace('\\n','')\n",
    "        if len(line) > 0:\n",
    "            raw_words = list(jieba.cut(line))\n",
    "#             print(raw_words)\n",
    "            dealed_words=[]\n",
    "            for word in raw_words:\n",
    "                if word not in stop_words:\n",
    "                    raw_word_list.append(word)\n",
    "                    dealed_words.append(word)\n",
    "            sentence_list.append(dealed_words)\n",
    "            \n",
    "        line = tr.readline()\n",
    "word_count=collections.Counter(raw_word_list)\n",
    "word_count=word_count.most_common(30000)\n",
    "word_list = [x[0] for x in word_count]\n",
    "\n",
    "print(len(word_list))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "class word2vec():\n",
    "    def __init__(self, \n",
    "                vocab_list = None,\n",
    "                embedding_size = 200,\n",
    "                win_len = 3,\n",
    "                learning_rate = 1,\n",
    "                num_neg_sample = 100):\n",
    "        self.batch_size = None\n",
    "        assert type(vocab_list) == list\n",
    "        self.vocab_list = vocab_list\n",
    "        self.vocab_size = len(vocab_list)\n",
    "        self.embedding_size = embedding_size\n",
    "        self.learning_rate = learning_rate\n",
    "        self.num_neg_sample = num_neg_sample\n",
    "        self.win_len = win_len\n",
    "        \n",
    "        self.word2id = {}\n",
    "        for i in range (self.vocab_size):\n",
    "            self.word2id[self.vocab_list[i]]=i\n",
    "    \n",
    "#     build_graph()\n",
    "    \n",
    "    def build_graph(self):\n",
    "        self.graph = tf.Graph()\n",
    "        with self.graph.as_default():\n",
    "            self.train_inputs = tf.placeholder(tf.int32, shape = [self.batch_size])\n",
    "            self.train_lables = tf.placeholder(tf.int32, shape = [self.batch_size,1])\n",
    "        \n",
    "        print(train_inputs)\n",
    "        print(train_labels)\n",
    "#         print(self.word2id)\n",
    "        \n",
    "#     def printme(self):\n",
    "#         print(\"haha\")\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "w2v = word2vec(vocab_list = word_list,\n",
    "              embedding_size = 200,\n",
    "              learning_rate = 1,\n",
    "              num_neg_sample = 100\n",
    "              )\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor 'Placeholder:0' shape=(5,) dtype=int32>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tf.placeholder(tf.int32, shape = [5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
